package com.storage.system.vo;

import com.storage.common.utils.StringUtils;
import com.storage.system.domain.StorageUser;
import io.swagger.annotations.ApiModelProperty;
import org.apache.commons.lang3.RandomStringUtils;

import java.io.Serializable;

/**
 * 用户表 storage_user VO
 *
 * @author storage
 * @date 2019-08-18
 */
public class StorageUserVO implements Serializable {
    private static final long serialVersionUID = 1L;

    /**
     * 用户id
     */
    @ApiModelProperty(value = "用户id")
    private Long id;
    /**
     * 昵称
     */
    @ApiModelProperty(value = "昵称")
    private String nickName;
    /**
     * 密码
     */
    @ApiModelProperty(value = "密码")
    private String password;
    /**
     * 电话
     */
    @ApiModelProperty(value = "电话")
    private String phone;
    /**
     * 邀请码
     */
    @ApiModelProperty(value = "邀请码")
    private String invitationCode;
    /**
     * 业务员编码
     */
    @ApiModelProperty(value = "业务员编码")
    private String businessCode;
    /**
     * 头像url
     */
    @ApiModelProperty(value = "头像")
    private String avatar;
    /**
     * 地址
     */
    @ApiModelProperty(value = "地址")
    private String address;
    /**
     * 邮箱
     */
    @ApiModelProperty(value = "邮箱")
    private String email;
    /**
     * 传真
     */
    @ApiModelProperty(value = "传真")
    private String fax;
    /**
     * 来源(自己注册的默认为空;上下级邀请注册填写对应的电话号码;推广业务员邀请注册填写业务员的invitation_code)
     */
    @ApiModelProperty(value = "来源(自己注册的默认为空;上下级邀请注册填写对应的电话号码;推广业务员邀请注册填写业务员的invitation_code)")
    private String source;
    /**
     * 微信code
     */
    @ApiModelProperty(value = "微信code")
    private String wxCode;
    /**
     * 记住密码
     */
    private Boolean rememberMe;
    /**
     * 验证码
     */
    private String identifyCode;

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getPassword() {
        return password;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public Boolean getRememberMe() {
        return rememberMe;
    }

    public void setRememberMe(Boolean rememberMe) {
        this.rememberMe = rememberMe;
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getNickName() {
        return nickName;
    }

    public void setNickName(String nickName) {
        this.nickName = nickName;
    }

    public String getBusinessCode() {
        return businessCode;
    }

    public void setBusinessCode(String businessCode) {
        this.businessCode = businessCode;
    }

    public String getAvatar() {
        return avatar;
    }

    public void setAvatar(String avatar) {
        this.avatar = avatar;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public String getFax() {
        return fax;
    }

    public void setFax(String fax) {
        this.fax = fax;
    }

    public String getSource() {
        return source;
    }

    public void setSource(String source) {
        this.source = source;
    }

    public String getInvitationCode() {
        return invitationCode;
    }

    public void setInvitationCode(String invitationCode) {
        this.invitationCode = invitationCode;
    }

    public String getWxCode() {
        return wxCode;
    }

    public void setWxCode(String wxCode) {
        this.wxCode = wxCode;
    }

    public String getIdentifyCode() {
        return identifyCode;
    }

    public void setIdentifyCode(String identifyCode) {
        this.identifyCode = identifyCode;
    }

    public StorageUser toRegisterDO(StorageUserVO vo) {
        StorageUser storageUserDO = new StorageUser();
        storageUserDO.setId(vo.getId());
        storageUserDO.setWxCode(vo.getWxCode());
        if (StringUtils.isBlank(vo.getNickName())) {
            // 设计随机默认昵称
            String randomKey = RandomStringUtils.randomAlphabetic(10);
            storageUserDO.setNickName(randomKey);
        } else {
            storageUserDO.setNickName(vo.getNickName());
        }

        if (StringUtils.isBlank(vo.getAvatar())) {
            // 没有头像默认头像
            storageUserDO.setAvatar("https://cdn.nlark.com/yuque/0/2019/jpeg/289151/1566717743046-0905e6a2-1ef3-4dcf-87ba-7ccd9dace657.jpeg");
        } else {
            storageUserDO.setAvatar(vo.getAvatar());
        }

        storageUserDO.setPhone(vo.getPhone());
        storageUserDO.setSource(vo.getBusinessCode());
        storageUserDO.setPassword(vo.getPassword());
        // 自己注册的都是代理商
        storageUserDO.setRole(3);

        return storageUserDO;
    }

    public static void main(String[] args) {
        System.out.print(RandomStringUtils.randomAlphabetic(10));
    }
}
